﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PercentChangeLabel.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="PriceBox" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Common.Controls
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;

    /// <summary>
    /// Defines the <seealso cref="PercentChangeLabel"/> type.
    /// </summary>
    public class PercentChangeLabel : Control
    {
        /// <summary>
        /// Member variable ValueProperty
        /// </summary>
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(decimal), typeof(PercentChangeLabel), new PropertyMetadata(0m));

        /// <summary>
        /// Member variable BkgImageProperty
        /// </summary>
        public static readonly DependencyProperty DefaultImageProperty = DependencyProperty.Register("DefaultImage", typeof(ImageSource), typeof(PercentChangeLabel), new PropertyMetadata(new BitmapImage(new Uri("Pack://application:,,,/Hisaab.Client.Common;component/Resources/Images/46/Bar.png"))));

        /// <summary>
        /// Member variable UpImageProperty
        /// </summary>
        public static readonly DependencyProperty UpImageProperty = DependencyProperty.Register("UpImage", typeof(ImageSource), typeof(PercentChangeLabel), new PropertyMetadata(new BitmapImage(new Uri("Pack://application:,,,/Hisaab.Client.Common;component/Resources/Images/64/Up.png"))));

        /// <summary>
        /// Member variable DownImageProperty
        /// </summary>
        public static readonly DependencyProperty DownImageProperty = DependencyProperty.Register("DownImage", typeof(ImageSource), typeof(PercentChangeLabel), new PropertyMetadata(new BitmapImage(new Uri("Pack://application:,,,/Hisaab.Client.Common;component/Resources/Images/64/Down.png"))));

        /// <summary>
        /// Member variable DisplayImageProperty
        /// </summary>
        public static readonly DependencyProperty DisplayImageProperty = DependencyProperty.Register("DisplayImage", typeof(ImageSource), typeof(PercentChangeLabel));

        /// <summary>
        /// Initializes static members of the <see cref="PercentChangeLabel"/> class.
        /// </summary>
        static PercentChangeLabel()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(PercentChangeLabel), new FrameworkPropertyMetadata(typeof(PercentChangeLabel)));
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PercentChangeLabel"/> class.
        /// </summary>
        public PercentChangeLabel()
        {
            DataContext = this;
        }

        /// <summary>
        /// Gets or sets up image.
        /// </summary>
        /// <value>
        /// Up image.
        /// </value>
        public ImageSource UpImage
        {
            get { return (ImageSource)GetValue(UpImageProperty); }
            set { SetValue(UpImageProperty, value); }
        }

        /// <summary>
        /// Gets or sets down image.
        /// </summary>
        /// <value>
        /// Down image.
        /// </value>
        public ImageSource DownImage
        {
            get { return (ImageSource)GetValue(DownImageProperty); }
            set { SetValue(DownImageProperty, value); }
        }

        /// <summary>
        /// Gets or sets the default image.
        /// </summary>
        /// <value>
        /// The default image.
        /// </value>
        public ImageSource DefaultImage
        {
            get { return (ImageSource)GetValue(DefaultImageProperty); }
            set { SetValue(DefaultImageProperty, value); }
        }

        /// <summary>
        /// Gets or sets the price.
        /// </summary>
        /// <value>
        /// The price.
        /// </value>
        public decimal Value
        {
            get
            {
                return (decimal)GetValue(ValueProperty);
            }

            set
            {
                if (value < 0)
                {
                    SetValue(DisplayImageProperty, GetValue(DownImageProperty));
                }
                else if (value > 0)
                {
                    SetValue(DisplayImageProperty, GetValue(UpImageProperty));
                }
                else
                {
                    SetValue(DisplayImageProperty, GetValue(DefaultImageProperty));
                }

                SetValue(ValueProperty, value);
            }
        }
    }
}